package linkedlist.leetcode_203;

public class OnlyPointer {
    public ListNode removeElements(ListNode head, int val) {
        if (head == null) {
            return null;
        }
        ListNode dummyNode = new ListNode(-1);
        dummyNode.next = head;
        ListNode pre = dummyNode;
        while (pre != null) {
            while (pre.next != null && pre.next.val == val) {
                pre.next = pre.next.next;
            }
            pre = pre.next;
        }
        return dummyNode.next;
    }
}
